<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="发货编码" prop="nos">
        <el-input v-model="queryParams.nos" placeholder="请输入发货编码" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="订单编号" prop="projectNos">
        <el-input v-model="queryParams.projectNos" placeholder="请输入订单编号" clearable
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="发货日期" prop="fahuoDate">
        <el-date-picker clearable v-model="queryParams.fahuoDate" type="date" value-format="yyyy-MM-dd"
                        placeholder="请选择发货日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="交货日期">
        <el-date-picker v-model="dateRange" style="display: flex;" value-format="yyyy-MM-dd" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="联系人" prop="linkman">
        <el-input v-model="queryParams.linkman" placeholder="请输入联系人" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="联系电话" prop="linktel">
        <el-input v-model="queryParams.linktel" placeholder="请输入联系电话" clearable
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="发运方式" prop="shipType">
        <el-input v-model="queryParams.shipType" placeholder="请输入发运方式" clearable
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange"
              :max-height="tableMaxHeight" ref="table"  @sort-change="handleSortChange">
      <el-table-column label="序号" type="index" width="55" align="center"/>
      <el-table-column  label="发货编码" align="center" prop="nos" show-overflow-tooltip/>
      <el-table-column  label="订单编号" align="center" prop="projectNos" show-overflow-tooltip/>
      <el-table-column  label="业务员" align="center" prop="saleman"/>
      <el-table-column  label="发货日期" align="center" prop="fahuoDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fahuoDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column sortable label="交货日期" align="center" prop="jiaohuoDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jiaohuoDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column  label="联系电话" align="center" prop="linktel"/>
      <el-table-column  label="发货状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yifahuo_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column sortable label="客户名称" align="center" prop="kehuName" show-overflow-tooltip/>
      <el-table-column align="center" label="到货回执" prop="daohuoFile" show-overflow-tooltip>
        <template slot-scope="scope">
          <file-upload-show :value="scope.row.daohuoFile"></file-upload-show>
        </template>
      </el-table-column>
      <el-table-column label="发运方式" align="center" prop="shipType" show-overflow-tooltip/>
      <el-table-column  label="发货金额" align="center" prop="allMoney"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" >
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-document" @click="xiangqing(scope.row)">发货单详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <lv-yifahuomingxi-list-module ref="fahuomingxiList"></lv-yifahuomingxi-list-module>
  </div>
</template>

<script>
import {deleteAction,getAction} from '@/api/manage'
import YiFahuoList from '@/views/develop/lvYifahuomingxi/YiFahuoList'
import {list} from "@/api/develop/lvYifahuo";
import FileUploadShow from "@/components/FileUpload/FileUploadShow.vue";
import LvYifahuomingxiListModule from "@/views/develop/lvYifahuomingxi/module/LvYifahuomingxiListModule.vue";

export default {
  name: "LvYifahuoListForFinance",
  dicts: ['yifahuo_status'],
  components: {
    LvYifahuomingxiListModule,
    FileUploadShow,
    YiFahuoList,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 发货单表格数据
      dataList: [],
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nos: null,
        projectNos: null,
        name: null,
        fahuoDate: null,
        jiaohuoDate: null,
        linkman: null,
        linktel: null,
        address: null,
        status: null,
        jingli: null,
        kehuId: null,
        kehuName: null,
        taxNo: null,
        taxCode: null,
        taxDate: null,
        taxMoney: null,
        taxShengyu: null,
        taxAllmoeny: null,
        allMoney: null,
        shengyu: null,
        yihui: null,
        daohuoDate: null,
        daohuoFile: null,
        tongzhiId: null,
        tongzhiNo: null,
        shipType: null,
        orderByColumn: "nos",
        isAsc: "desc"
      },
      url: {
        list: '/lvYifahuo/lvYifahuo/list',
      },
      tableMaxHeight: window.innerHeight - 320,
    };
  },
  created() {
    this.getList();
  },
  methods: {

    xiangqing(row) {
      this.$refs.fahuomingxiList.showMingxi(row);
    },
    /** 查询发货单列表 */
    getList() {
      this.loading = true;
      list(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getTableHeight() {
      this.tableHeight = window.innerHeight - 320
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.handleQuery();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      deleteAction(this.url.remove, id).then(response => {
        this.getList();
        this.$modal.msgSuccess("删除成功！");
      }).catch(() => {
      });
    },

  }
};
</script>
